import java.util.Random;

/**
 * @author junzhongliu
 * @date 2019/5/29 20:50
 */
public class CreateListByHeader {
    public static void main(String[] args) {
        ListNode header = createListByHeader(6);
        while (header!=null){
            System.out.println(header.val);
            header=header.next;
        }
    }

    public static ListNode createListByHeader(int length){
        ListNode header=null;
        ListNode tmpNode;
        Random random = new Random();
        for(int i=0;i<length;i++){
            ListNode newNode = new ListNode(random.nextInt(100));
            if(header==null){
                header=newNode;
            }else{
                tmpNode = header.next;
                header.next=newNode;
                newNode.next=tmpNode;
            }
            i++;
        }
        return header;
    }
}
